// 118. 杨辉三角

function generate(numRows: number): number[][] {
  // 错位相加
  if (!numRows) return [];
  const result = [[1]];

  while (result.length < numRows) {
    const arr1 = [...result[result.length - 1]];
    const arr2 = [...result[result.length - 1]];

    arr1.push(0);
    arr2.unshift(0);
    // console.log(arr1, arr2);
    const res = new Array(result.length + 1).fill(0);
    // console.log(res)
    for (let i = 0; i < res.length; i++) {
      // console.log(arr1[i], arr2[i]);
      res[i] = arr1[i] + arr2[i];
    }
    // console.log(res)
    result.push(res);
  }

  return result;
}

console.log(generate(3));
